What are the two ways of getting a source program to run on a computer system?

A good answer might be:

  1. Translation (into machine instructions.)
  2. Interpretation (by an interpreter program.)

Bytecodes

Java combines these ideas in a way that will take some explaining. To get the sample program running, it first is translated into bytecodes.

A Java bytecode is a machine instruction for a Java processor chip. The architecture of this processor has been very carefully described by the designers of Java and is freely available to anyone.

To run a Java program on the Java processor chip, the souce program (the text file) must be translated into bytecodes. (You will soon see that you do not actually need the Java processor chip in your computer to run Java.) Here is a picture of the sample Java program Hello.java being translated into bytecodes. The file of bytecodes (machine language for the Java chip) is called Hello.class.

In this picture, the source program Hello.java is examined by a program called javac running on your computer. The javac program is a compiler (a translator) that translates the source program into a bytecode file called Hello.class.

Important Idea: The bytecode file will contain exactly the same bytecodes no matter what computer system is used.

The Java compiler on a Macintosh will produce the exact same bytecodes as the Java compiler on an Intel system.

QUESTION 5:

(Review of Chapter 4:) Can these bytecodes be directly executed on a Macintosh or on an Intel processor? That is, can the file Hello.class be run on either system?